package com.business.systemmanage.controller;


import com.business.systemmanage.common.entity.ResponseInfo;
import com.business.systemmanage.entity.Organ;
import com.business.systemmanage.entity.UserInfo;
import com.business.systemmanage.service.IOrganService;
import com.business.systemmanage.vo.OrganVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 组织机构 前端控制器
 * </p>
 *
 * @author sixDog
 * @since 2019-04-12
 */
@RestController
@RequestMapping("/systemmanage/organ")
public class OrganController {
    @Autowired
    private IOrganService iOrganService;

    @ApiOperation(
            value = "根据机构id获取机构信息",
            notes = "机构id要填写整数哦",
            tags = {"机构"})
    @ApiImplicitParam(paramType = "query", name = "id", value = "id", required = true, dataType = "Long")
    @RequestMapping("/find")
    public ResponseInfo find(@RequestParam Long id) {
        try {
            final Organ organ = iOrganService.getById(id);
            return ResponseInfo.generateObjectRes(organ);
        } catch (Exception e) {
            return ResponseInfo.generateErrorRes(e.getMessage());
        }
    }

    @ApiOperation(
            value = "保存机构信息",
            notes = "插入机构id不要填写",
            tags = {"机构"})
    @RequestMapping("/insert")
    public ResponseInfo insert(@RequestBody OrganVO organVO) {
        try {
            iOrganService.insert(organVO);
            return ResponseInfo.generateSuccessRes();
        } catch (Exception e) {
            return ResponseInfo.generateErrorRes(e.getMessage());
        }
    }
}
